package com.lesama.file;

import java.io.File;
import java.util.Scanner;

public class FileTest1 {
    public static void main(String[] args) {
        // 键盘录入文件夹路径
        File directory = getDirectory();
        System.out.println(directory.getAbsoluteFile());
    }
    public static File getDirectory() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件夹路径");
        while (true) {
            String path = sc.next();
            File file = new File(path);
            if(!file.exists()) {
                System.out.println("您所输入的文件路径不存在,请重新输入");
            } else if(file.isFile()) {
                System.out.println("请输入一个文件夹路径");
            } else {
                return file;
            }
        }
    }
}
